package com.pai4j.pgc.service;

import com.pai4j.common.bean.PAIResponseBean;
import com.pai4j.common.bean.PAIResponseBeanUtil;
import com.pai4j.domain.vo.response.UserBaseResponseInfoVO;
import com.pai4j.remote.user.UserServiceClient;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;

@Service
public class AccountService {

    @Autowired
    private UserServiceClient userServiceClient;

    /**
     * 查询当前账号信息
     *
     * @param account
     * @return
     */

    public UserBaseResponseInfoVO accountInfo(String account) {

       PAIResponseBean<UserBaseResponseInfoVO> responseBean = userServiceClient.getUserBaseInfo(account);
        if (PAIResponseBeanUtil.isOk(responseBean)) {
            return responseBean.getData();
        }
        return null;
    }

    /**
     *  批量查询账号详情数据
     *
     * @param accounts
     * @return
     */
    public List<UserBaseResponseInfoVO> batchGetList(List<String> accounts) {
        if (CollectionUtils.isEmpty(accounts)) {
            return Collections.emptyList();
        }
        PAIResponseBean<List<UserBaseResponseInfoVO>> responseBean =
                userServiceClient.batchGetList(accounts);
        if (PAIResponseBeanUtil.isOk(responseBean)) {
            return responseBean.getData();
        }
        throw new RuntimeException(responseBean.getMessage());
    }
   /**
     *  批量查询账号详情数据
     *
     * @param accounts
     * @return
     */
    public Map<String, UserBaseResponseInfoVO> batchGet(Set<String> accounts) {
        if (CollectionUtils.isEmpty(accounts)) {
            return Collections.emptyMap();
        }
        PAIResponseBean<Map<String, UserBaseResponseInfoVO>> responseBean =
                userServiceClient.batchGetMap(accounts);
        if (PAIResponseBeanUtil.isOk(responseBean)) {
            return responseBean.getData();
        }
        throw new RuntimeException(responseBean.getMessage());
    }


}
